<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>echarts地图</title>
    <script src="../js/data.js"></script>
    <script src="../js/echarts.min.js"></script>
    <script src="../js/jquery.min.js"></script>
</head>

<body>
<div class="viewport" id="home">
    <div class="echarts" id="echarts"></div>
</div>
</body>
<script>
    // 图标资源
    var icon1 = ''

    // 获取数据
    function getData() {
        $.get('../js/data.json', function (data) {
            getEcharts(data)
        });
    }

    // 渲染echarts
    function getEcharts(data) {
        var chartDom = document.getElementById('echarts');
        var myChart = echarts.init(chartDom);
        var nameMap = '地图数据';
        echarts.registerMap(nameMap, data);
        /*获取地图数据*/
        var option = {
            tooltip: {
                trigger: 'item',
                triggerOn: 'click',
                showDelay: 0, //浮层显示的延迟
                transitionDuration: 0.1, // 提示框浮层的移动动画过渡时间
                enterable: true,
                formatter: function (params) {
                    console.log(params)
                    if (params.data) {
                        let info = params.data.info || {};
                        return info
                    } else {
                        return
                    }
                },
            },
            //地理坐标
            geo: {
                map: nameMap,
                type: "map",
                aspectScale: 0.75, //长宽比
                zoom: 1.1,
                roam: false,
                label: {
                    normal: {
                        show: true,
                        textStyle: {
                            color: '#fff'
                        }
                    },
                    emphasis: {
                        textStyle: {
                            color: '#01d6f6'
                        }
                    }
                },
                itemStyle: {
                    normal: {
                        borderColor: 'rgba(14, 34, 150, 1.00)',
                        borderWidth: 1,
                        areaColor: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0, color: 'rgba(0, 214, 246, 1.00)' // 0% 处的颜色
                            }, {
                                offset: 0.5, color: 'rgba(0, 214, 246, 1.00)' // 100% 处的颜色
                            }, {
                                offset: 1, color: 'rgba(3, 138, 252, 1.00)' // 100% 处的颜色
                            }]
                        )
                    },
                    emphasis: {
                        areaColor: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0, color: 'rgba(141, 59, 238, 1.00)' // 0% 处的颜色
                            }, {
                                offset: 0.5, color: 'rgba(117, 84, 240, 1.00)' // 100% 处的颜色
                            }, {
                                offset: 1, color: 'rgba(115, 86, 241, 1.00)' // 100% 处的颜色
                            }]
                        ),
                        borderWidth: 0
                    }
                },
            },
            series: [
                //标记 图形 原点 scatter点 effectScatter涟漪特效
                {
                    type: 'scatter',
                    coordinateSystem: 'geo',
                    symbolSize: 5,
                    label: {
                        normal: {
                            formatter: '{b}',
                            position: 'right',
                            show: true
                        },
                        emphasis: {
                            show: true
                        }
                    },
                    hoverAnimation: true,
                    itemStyle: {
                        normal: {
                            color: '#fff'
                        }
                    },
                    zlevel: 1,
                },
            ]
        };
        myChart.setOption(option);
    }

    if (window.location.origin == 'file://') {
        setTimeout(() => {
            getEcharts(gdMap)
        }, 100)
    } else {
        getData()
    }
</script>
</html>
<style>
    html, body {
        padding: 0;
        margin: 0;
    }

    #home {
        width: 100%;
        height: 100%;
        background: #0d1551;
        position: fixed;
    }

    .echarts {
        width: 100%;
        height: 100%;
        background: #0d1551;
        position: fixed;
    }

    .info {
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 10;
        color: red;
    }

    .links {
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 10;

    }

    .links a {
        text-decoration: none;
        color: #fff;
    }
</style>
